#!/bin/sh
# can modify
jar_file=ruoyi-admin.jar
server_name=ruoyi-admin
jvm_opt="-Xms512m -Xmx512m"

# can NOT modify
log_file=$server_name.log
app_home=`pwd`
jars_home=$app_home

start(){
	nohup java -Xbootclasspath/p:. -server $jvm_opt -Dloader.path=$jars_home/lib/ -jar $jars_home/$jar_file >> logs/$log_file 2>&1 &
	sleep 1
	javaps=`ps -ef | grep java | grep $jars_home/$jar_file`

	if [ -n "$javaps" ]; then
		psid=`echo $javaps | awk '{print $2}'`
	else
		psid=0
	fi
	echo "PID：$psid"
        echo "jar home: $jars_home"
	echo "$server_name already start"
}
# 停止服务
stop(){
	javaps=`ps -ef | grep java | grep $jars_home/$jar_file`
        if [ -n "$javaps" ]; then
		psid=`echo $javaps | awk '{print $2}'`
	else
		psid=0
	fi
	echo "PID：$psid"
	kill -9 $psid
	# kill  $psid
        echo "jar home: $jars_home"
	echo "$server_name already stop"
}

case "$1" in
   'start')
     start
      ;;
   'stop')
     stop
     ;;
   'restart')
     stop
     start
     ;;
  *)
     echo "Usage: $0 {start|stop|restart}"
     echo "start: start $server_name server"
     echo "stop: stop $server_name server"
     echo "restart: restart $server_name server"
     exit 1
esac
exit 0
